package nl.Viewer.Dialogs.DatasetSelection;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import nl.Viewer.SerializedObjects.Modality;
import nl.Viewer.SerializedObjects.Visualization;
import nl.Viewer.Sessions.Communication.ObjectTuple;

/**
 * Object used to transfer data while dragging-and-dropping
 * 
 * @author Jeroen Verschuur
 * 
 */

public class DatasetSelectionTransferObject implements Transferable {
   private final static String mimeType                    =
                                                              DataFlavor.javaJVMLocalObjectMimeType
                                                                 + ";class=nl.Viewer.Dialogs.DatasetSelection.DatasetSelectionTransferObject";
   public List<ObjectTuple>    visualizationsAndModalities = new ArrayList<ObjectTuple>();

   public DatasetSelectionTransferObject() {

   }

   public void addObject( Visualization v, Modality m ) {
      visualizationsAndModalities.add( new ObjectTuple( v, m ) );
   }

   public Object getTransferData( DataFlavor flavor ) throws UnsupportedFlavorException, IOException {
      return this;
   }

   public DataFlavor[] getTransferDataFlavors() {
      DataFlavor f;
      try {
         f = new DataFlavor( mimeType );
      }
      catch( Exception e ) {
         e.printStackTrace();
         return new DataFlavor[ 0 ];
      }

      return new DataFlavor[] { f };
   }

   public boolean isDataFlavorSupported( DataFlavor flavor ) {
      if( flavor.getMimeType().equals( mimeType ) ) {
         return true;
      }
      return false;
   }
}
